package cn.fengwoo.springBoot.controller;

import cn.fengwoo.springBoot.entity.Result;
import cn.fengwoo.springBoot.entity.User;
import cn.fengwoo.springBoot.enums.ResultEnum;
import cn.fengwoo.springBoot.utils.ResultUtil;
import cn.fengwoo.springBoot.utils.qiniu.QiniuUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 上传API
 * Created by FancyFong on 18/1/2018.
 */

@RestController
@RequestMapping("/file")
@Api(value = "/UploadApiController", description = "文件上传管理")
public class UploadApiController {

    @Value("${qiniu.access-key}")
    private String accessKey;
    @Value("${qiniu.secret-key}")
    private String secretkey;
    @Value("${qiniu.bucket}")
    private String bucket;
    @Value("${qiniu.qiniu-cdn}")
    private String qiniuCDN;



    @ApiOperation(value="Base64方式图片上传")
    @PostMapping("/base_upload")
    public Result<User> login(@ApiParam(value = "Base64字符串",required = true) @RequestParam(value = "base64Str", required = true) String base64Str){
        QiniuUtil qiniuUtil = new QiniuUtil(accessKey,secretkey,bucket,qiniuCDN);
        String url = qiniuUtil.uploadBaseImage(base64Str);
        return ResultUtil.success(ResultEnum.SUCCESS,url);
    }


}
